#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=10010;
bool h[maxn];
struct node
{
	int x,y;
	bool friend operator<(node a,node b)
	{
		return a.x>b.x;
	}
}a[maxn];
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		memset(h,0,sizeof(h));
		for(int i=1;i<=n;i++)
		   scanf("%d%d",&a[i].x,&a[i].y);
		sort(a+1,a+n+1);
		long long ans=0;
		
		for(int i=1;i<=n;i++)
		{
			bool f=false;
			for(int j=a[i].y;j>=1;j--)
				if(!h[j]){f=true;h[j]=true;break;}
			if(f)ans+=a[i].x;
		}			
		printf("%lld\n",ans);
	}
	return 0;
}
